<template>
	<div v-show="show" class="emotion-overlay" @click="close()">
		<div class="emotion-box" @click.stop>
			<el-scrollbar style="height: 220px">
				<div class="emotion-items">
					<div class="emotion-item" v-for="(emoText, i) in $emo.emoTextList" :key="i"
						@click="onClickEmo(emoText)" v-html="$emo.textToImg(emoText, 'emoji-large')">
					</div>
				</div>
			</el-scrollbar>
		</div>
	</div>
</template>

<script>
export default {
	name: "emotion",
	data() {
		return {
			show: false
		}
	},
	methods: {
		onClickEmo(emoText) {
			let emotion = `#${emoText};`
			this.$emit('emotion', emotion)
			this.close(); // 选择表情后自动关闭
		},
		open() {
			this.show = true;
		},
		close() {
			this.show = false;
		}
	}
}
</script>
<style scoped lang="scss">
.emotion-overlay {
	position: absolute;
	top: 0;
	left: 0;
	right: 0;
	bottom: 0;
	z-index: 1000;
}

.emotion-box {
	position: absolute;
	bottom: 10px;
	/* 距离工具栏10px */
	left: 10px;
	width: 372px;
	box-sizing: border-box;
	padding: 10px;
	background-color: #fff;
	border: 1px solid #e0e0e0;
	border-radius: 8px;
	box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
	z-index: 1001;

	.emotion-items {
		display: flex;
		flex-wrap: wrap;
		gap: 2px;

		.emotion-item {
			display: flex;
			align-items: center;
			justify-content: center;
			width: 32px;
			height: 32px;
			text-align: center;
			cursor: pointer;
			border-radius: 4px;
			transition: background-color 0.2s;

			&:hover {
				background-color: #f5f5f5;
			}
		}
	}
}

/* 深色模式适配 */
:root[data-theme="dark"] {
	.emotion-box {
		background-color: #2c2c2c;
		border-color: #404040;

		.emotion-item:hover {
			background-color: #404040;
		}
	}
}
</style>
